package com.zhuang.compare.service;

import com.zhuang.compare.bean.BeanInterface;
import com.zhuang.compare.bean.MileBean;
import com.zhuang.compare.enums.BasenumEnum;
import com.zhuang.compare.enums.BeanEnum;

/**
 * Created by zhuanglei on 15/4/16.
 */
public class CompareServiceImpl implements CompareService {

    private GenerateService generateService;

    public CompareServiceImpl(GenerateService generateService) {
        this.generateService = generateService;
    }


    @Override
    public boolean compare(String value, String value2) {
        if (getBeanValue(value) == getBeanValue(value2)) {
            return true;
        }

        return false;
    }

    private float getBeanValue(String value) {
        String[] markers = value.split(" ");
        float result = 0f;
        BeanInterface bean = generateService.getModelBean(markers[1], Float.valueOf(markers[0]));
        result = generateService.getModelBean(markers[1], Float.valueOf(markers[0])).getValueMultiBaseNumber(getBasenumByBeantype(markers[1]));
        return result;
    }

    private int getBasenumByBeantype(String keyName) {
        for (BasenumEnum beanEnum : BasenumEnum.values()) {
            if (keyName.equalsIgnoreCase(beanEnum.getBeanType())) {
                return beanEnum.getBaseNumber();
            }
        }

        return 0;
    }
}
